\doxysection{x\+Task\+Create }
\hypertarget{group__x_task_create}{}\label{group__x_task_create}\index{xTaskCreate@{xTaskCreate}}
task. h 
\begin{DoxyPre}
BaseType\_t xTaskCreate(                           TaskFunction\_t pvTaskCode,                           const char * const pcName,                           configSTACK\_DEPTH\_TYPE usStackDepth,                           void *pvParameters,                           UBaseType\_t uxPriority,                           TaskHandle\_t *pvCreatedTask                       );\end{DoxyPre}


Create a new task and add it to the list of tasks that are ready to run.

Internally, within the Free\+RTOS implementation, tasks use two blocks of memory. The first block is used to hold the task\textquotesingle{}s data structures. The second block is used by the task as its stack. If a task is created using x\+Task\+Create() then both blocks of memory are automatically dynamically allocated inside the x\+Task\+Create() function. (see \href{http://www.freertos.org/a00111.html}{\texttt{http\+://www.\+freertos.\+org/a00111.\+html}}). If a task is created using x\+Task\+Create\+Static() then the application writer must provide the required memory. x\+Task\+Create\+Static() therefore allows a task to be created without using any dynamic memory allocation.

See x\+Task\+Create\+Static() for a version that does not use any dynamic memory allocation.

x\+Task\+Create() can only be used to create a task that has unrestricted access to the entire microcontroller memory map. Systems that include MPU support can alternatively create an MPU constrained task using x\+Task\+Create\+Restricted().


\begin{DoxyParams}{Parameters}
{\em pv\+Task\+Code} & Pointer to the task entry function. Tasks must be implemented to never return (i.\+e. continuous loop).\\
\hline
{\em pc\+Name} & A descriptive name for the task. This is mainly used to facilitate debugging. Max length defined by config\+MAX\+\_\+\+TASK\+\_\+\+NAME\+\_\+\+LEN -\/ default is 16.\\
\hline
{\em us\+Stack\+Depth} & The size of the task stack specified as the number of variables the stack can hold -\/ not the number of bytes. For example, if the stack is 16 bits wide and us\+Stack\+Depth is defined as 100, 200 bytes will be allocated for stack storage.\\
\hline
{\em pv\+Parameters} & Pointer that will be used as the parameter for the task being created.\\
\hline
{\em ux\+Priority} & The priority at which the task should run. Systems that include MPU support can optionally create tasks in a privileged (system) mode by setting bit port\+PRIVILEGE\+\_\+\+BIT of the priority parameter. For example, to create a privileged task at priority 2 the ux\+Priority parameter should be set to ( 2 \texorpdfstring{$\vert$}{|} port\+PRIVILEGE\+\_\+\+BIT ).\\
\hline
{\em pv\+Created\+Task} & Used to pass back a handle by which the created task can be referenced.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pd\+PASS if the task was successfully created and added to a ready list, otherwise an error code defined in the file \doxylink{projdefs_8h_source}{projdefs.\+h}
\end{DoxyReturn}
Example usage\+: 
\begin{DoxyPre}
// Task to be created.
void vTaskCode( void * pvParameters )
\{
    for( ;; )
    \{
     // Task code goes here.
    \}
\}

// Function that creates a task.
void vOtherFunction( void )
\{
static uint8\_t ucParameterToPass;
TaskHandle\_t xHandle = NULL;

    // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass
    // must exist for the lifetime of the task, so in this case is declared static.  If it was just an
    // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
    // the new task attempts to access it.
    xTaskCreate( vTaskCode, "{}NAME"{}, STACK\_SIZE, \&ucParameterToPass, tskIDLE\_PRIORITY, \&xHandle );
    configASSERT( xHandle );

    // Use the handle to delete the task.
    if( xHandle != NULL )
    \{
        vTaskDelete( xHandle );
    \}
\}
  \end{DoxyPre}
 